package main

import "fmt"

/*
	GO语言的结构体嵌套：
		1. 模拟继承性: is - a
			type A struct {
				field
			}
			type B struct {
				A  // 匿名字段
            }
		2. 模拟聚合关系: has - a
			type C struct {
				field
			}
			type D struct {
				c C
			}
*/

// 定义父类
type Person struct {
	name string
	age  int
}

func (p *Person) eat() {
	fmt.Println("父类 eat")
	fmt.Println(p.name)
}

// 定义子类
type Student struct {
	Person // 匿名字段，模拟继承
	school string
}

func main() {
	p1 := Student{
		Person: Person{age: 22},
		school: "hhh",
	}
	p1.eat()
	fmt.Println(p1)
}
